package com.kwan.x_im.main.mode;

import android.app.Application;

import com.kwan.x_im.data.DataManager;
import com.kwan.x_im.data.IMViewMode;
import com.kwan.x_im.data.http.ApiService;
import com.kwan.xframe.api.DataSubscriber;
import com.kwan.xframe.api.DataSubscriberListener;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import androidx.annotation.NonNull;
import io.reactivex.rxjava3.core.Flowable;
import timber.log.Timber;

public class MainViewMode extends IMViewMode {

	public MainViewMode(@NonNull Application application) {
		super(application);
	}

	public void checkToken(String idToken) {
		ApiService.FUNC func = ApiService.FUNC.CheckToken;
		execute(DataManager.getInstance().checkToken(idToken), getHttpCallBack(func));
	}

	public void orderSn(String googleUserId, String productId) {
		ApiService.FUNC func = ApiService.FUNC.OrderSn;
		func.extra.put("productId", productId);
		execute(DataManager.getInstance().orderSn(googleUserId, productId), getHttpCallBack(func));
	}

	public void purchaseChapter(String googleUserId, String novelId, String chapterIds) {
		execute(DataManager.getInstance().purchaseChapter(googleUserId, novelId, chapterIds), getHttpCallBack(ApiService.FUNC.PurchaseChapter));
	}


	public void test(String id) {


		execute(Flowable.timer(10, TimeUnit.SECONDS), new DataSubscriber<>(new DataSubscriberListener<>() {
			@Override
			public void onDataCompleted(int vocational_id, HashMap<String, Object> exData) {
				Timber.e("onDataCompleted..");
			}

			@Override
			public void onDataError(int vocational_id, HashMap<String, Object> exData, Throwable throwable) {
				Timber.e("onDataError..");
			}

			@Override
			public void onDataNext(int vocational_id, HashMap<String, Object> exData, Long data) {

				Timber.e("onDataNext..");
			}
		}));
	}

}
